package com.ruoyi.web.controller.mes;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.kt.mes.domain.ProlSiteAct;
import com.kt.mes.service.IProlSiteActService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工位动作设定Controller
 *
 * @author lzc
 * @date 2021-01-14
 */
@RestController
@RequestMapping("/mes/site_act")
public class ProlSiteActController extends BaseController
{
    @Autowired
    private IProlSiteActService prolSiteActService;

    /**
     * 查询工位动作设定列表
     */
   // @PreAuthorize("@ss.hasPermi('mes:site_act:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProlSiteAct prolSiteAct)
    {
        startPage();
        List<ProlSiteAct> list = prolSiteActService.selectProlSiteActList(prolSiteAct);
        return getDataTable(list);
    }

    /**
     * 导出工位动作设定列表
     */
   // @PreAuthorize("@ss.hasPermi('mes:site_act:export')")
    @Log(title = "工位动作设定", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ProlSiteAct prolSiteAct)
    {
        List<ProlSiteAct> list = prolSiteActService.selectProlSiteActList(prolSiteAct);
        ExcelUtil<ProlSiteAct> util = new ExcelUtil<ProlSiteAct>(ProlSiteAct.class);
        return util.exportExcel(list, "site_act");
    }

    /**
     * 获取工位动作设定详细信息
     */
  //  @PreAuthorize("@ss.hasPermi('mes:site_act:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(prolSiteActService.selectProlSiteActById(id));
    }

    /**
     * 新增工位动作设定
     */
  //  @PreAuthorize("@ss.hasPermi('mes:site_act:add')")
    @Log(title = "工位动作设定", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProlSiteAct prolSiteAct)
    {
        //proActId 唯一
        ProlSiteAct query=new ProlSiteAct();
        query.setProActId(prolSiteAct.getProActId());
        if(prolSiteActService.selectProlSiteActList(query).isEmpty()==false){

            return AjaxResult.error("编号已存在");
        }


        return toAjax(prolSiteActService.insertProlSiteAct(prolSiteAct));
    }

    /**
     * 修改工位动作设定
     */
   // @PreAuthorize("@ss.hasPermi('mes:site_act:edit')")
    @Log(title = "工位动作设定", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProlSiteAct prolSiteAct)
    {
        return toAjax(prolSiteActService.updateProlSiteAct(prolSiteAct));
    }

    /**
     * 删除工位动作设定
     */
  //  @PreAuthorize("@ss.hasPermi('mes:site_act:remove')")
    @Log(title = "工位动作设定", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(prolSiteActService.deleteProlSiteActByIds(ids));
    }
}
